{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8b8d7b17-af50-42cd-b531-ef61c49c9e61",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set the work directory to the imaginaire root.\n",
    "import os, sys, time\n",
    "import pathlib\n",
    "root_dir = pathlib.Path().absolute().parents[2]\n",
    "os.chdir(root_dir)\n",
    "print(f\"Root Directory Path: {root_dir}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2b5b9e2f-841c-4815-92e0-0c76ed46da62",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import Python libraries.\n",
    "import numpy as np\n",
    "import trimesh\n",
    "import k3d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84604c4a-8d95-462a-b7f0-acaa0b9f563d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the 3D mesh.\n",
    "ply_fname = \"logs/0_debug/18/mesh.ply\"\n",
    "mesh = trimesh.load(ply_fname)\n",
    "print(f\"# vertices: {len(mesh.vertices)}\")\n",
    "print(f\"# faces: {len(mesh.faces)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d1f8df0b-8361-40f3-a801-0cc42b920fed",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Visualize with K3D.\n",
    "plot = k3d.plot(name=\"mesh\", height=800, camera_rotate_speed=5.0, camera_zoom_speed=3.0, camera_pan_speed=1.0)\n",
    "C = mesh.visual.vertex_colors\n",
    "colors = C[:,0]*256**2 + C[:,1]*256 + C[:,2]\n",
    "plot += k3d.mesh(mesh.vertices, mesh.faces, colors=colors, side=\"double\", opacity=1)\n",
    "plot.display()\n",
    "plot.camera_fov = 30.0"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
